package JAVA300.第十章IO;

import java.io.*;

/**
 * 字节数组流p178
 */

public class IO_Study07 {
    public static void main(String[] args) {

       // inputTest("字节数组流的测试输入");
        outputTest();



    }

    public static void inputTest(String input){

        byte[] src = input.getBytes();

        InputStream inputStream = null;

        try {
            inputStream = new ByteArrayInputStream(src);

            byte[] flush = new byte[1024];
            int len = -1;
            while ((len = inputStream.read(flush))!= -1){
                String str = new String(flush,0,len);
                System.out.println(str);

            }
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            //不用进行关闭操作
        }


    }

    public static void outputTest(){
        byte[] dest = null;
        //为了使用BA类中特有的toByteArray方法，所以不用父类生命
        ByteArrayOutputStream baos = null;
        try {
            baos = new ByteArrayOutputStream();

            String msg = "韩圈圈";
            byte[] datas = msg.getBytes();
            baos.write(datas,0,datas.length);
            baos.flush();
            //获取数据
            dest = baos.toByteArray();
            System.out.println(dest.length);//9
            System.out.println(new String(dest,0,dest.length));
        }catch (IOException e){
            e.printStackTrace();
        }finally {

        }






    }
}
